﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MvcHeatloss.Models
{
    [MetadataType(typeof(WallData))]
    public partial class Wall
    {
        public ProjectEntities db = new ProjectEntities();
        
        public Wall(double height, double width, string type, string temp)
        {
            WallArea = height * width;
            WallType = type;
            WallUValue = (double)db.UValues.Where(d => d.Description == type).Select(u => u.UValue1).First();
            WallTemp = Int32.Parse(temp);
            WallHeatloss = CalcHeatoss.FabricHeatloss(this.WallUValue, this.WallArea, this.WallTemp);
        }
        public Wall(): base()
        {
        }

        // Wall type
        public string WallType { get; set; }
        // Wall area
        public double WallArea { get; set; }
        // Wall temperature difference
        public int WallTemp { get; set; }
        //
        public double WallUValue { get; set; }

        double wallHeatloss;
        public double WallHeatloss 
        { 
            get
            {
                return wallHeatloss;
            }
            set
            {
                wallHeatloss = CalcHeatoss.FabricHeatloss(this.WallUValue, this.WallArea, this.WallTemp);
            }
        }
       

    }
    public class WallData
    {
        [Required(ErrorMessage = "You must enter a Wall Length")]
        [Display(Name = "Wall Length")]
        public decimal Length { get; set; }

        [Display(Name = "Wall Height")]
        public decimal Height { get; set; }

    }
}
